import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

class NoReply extends StatefulWidget {
  const NoReply({Key? key}) : super(key: key);

  @override
  State<NoReply> createState() => _NoReplyState();
}

class _NoReplyState extends State<NoReply> {
  List<String> rank = ['全部 360', '五星 21', '四星 102', '三星 201', '二星 11', '一星 17'];

  int rankIndex = 0;

  int _singleSelectedIndex = -1;

  List<String> urls = [
    'https://img1.baidu.com/it/u=3033226715,2238019049&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500',
    'https://img0.baidu.com/it/u=2718980415,581692139&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500',
    'https://img2.baidu.com/it/u=3308284036,3855849897&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800',
    'https://img2.baidu.com/it/u=4109695418,2044247650&fm=253&fmt=auto&app=138&f=JPEG?w=667&h=500'
  ];

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          Container(
            decoration: const BoxDecoration(color: Colors.white),
            padding:
                const EdgeInsets.symmetric(vertical: Sizes.default10, horizontal: Sizes.default15),
            child: ListBody(
              children: [
                Container(
                  alignment: Alignment.centerLeft,
                  padding: const EdgeInsets.only(bottom: Sizes.default10),
                  child: Wrap(
                    spacing: Sizes.default10,
                    runSpacing: Sizes.default12,
                    children: rank
                        .asMap()
                        .map((index, item) => MapEntry(
                            index,
                            InkWell(
                              child: Container(
                                constraints: const BoxConstraints.expand(width: 100, height: 25),
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(Sizes.default5),
                                    border: Border.all(
                                        color: index == rankIndex
                                            ? ColorsUtils.rgba(255, 110, 83, 1)
                                            : ColorsUtils.rgba(215, 215, 215, 1))),
                                child: Text(
                                  item,
                                  style: StylesUtils.customTextStyle(
                                      color: index == rankIndex
                                          ? ColorsUtils.colorFf6
                                          : ColorsUtils.color797),
                                ),
                              ),
                              onTap: () {
                                setState(() {
                                  rankIndex = index;
                                });
                              },
                            )))
                        .values
                        .toList(),
                  ),
                ),
                Row(
                  children: [
                    BrnRadioButton(
                      radioIndex: 0,
                      isSelected: _singleSelectedIndex == 0,
                      child: Padding(
                        padding: const EdgeInsets.only(left: 5),
                        child: Text(
                          '有内容的评价',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default12, color: ColorsUtils.color515),
                        ),
                      ),
                      onValueChangedAtIndex: (index, value) {
                        setState(() {
                          _singleSelectedIndex = index;
                        });
                      },
                    ),
                    const SizedBox(
                      width: 20,
                    ),
                    BrnRadioButton(
                      radioIndex: 1,
                      isSelected: _singleSelectedIndex == 1,
                      child: Padding(
                        padding: const EdgeInsets.only(left: 5),
                        child: Text(
                          '有图片的评价',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default12, color: ColorsUtils.color515),
                        ),
                      ),
                      onValueChangedAtIndex: (index, value) {
                        setState(() {
                          _singleSelectedIndex = index;
                        });
                      },
                    ),
                  ],
                )
              ],
            ),
          ),
          Container(
            decoration: const BoxDecoration(
              color: Colors.white,
            ),
            margin: const EdgeInsets.only(top: Sizes.default10),
            padding: const EdgeInsets.only(
                bottom: Sizes.default10,
                right: Sizes.default15,
                left: Sizes.default15,
                top: Sizes.default20),
            child: ListBody(
              children: [
                SizedBox(
                  height: Sizes.default40,
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      GFAvatar(
                        backgroundImage: ToolsUtils.assetImage('user_header.jpg'),
                        size: GFSize.LARGE,
                      ),
                      Expanded(
                          child: Column(
                        children: [
                          Container(
                            height: Sizes.default20,
                            alignment: Alignment.topLeft,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Text(
                                  '匿名用户',
                                  style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                                ),
                                InkWell(
                                    onTap: () {
                                      Get.toNamed(RouteGet.evaluateInfo);
                                    },
                                    child: Text.rich(TextSpan(
                                        text: '详情',
                                        style: StylesUtils.customTextStyle(
                                            color: ColorsUtils.color797, fontSize: Sizes.default12),
                                        children: [
                                          WidgetSpan(
                                              child: BrunoTools.getAssetSizeImage(
                                                  BrnAsset.iconRightArrow,
                                                  Sizes.default14,
                                                  Sizes.default14),
                                              alignment: PlaceholderAlignment.middle)
                                        ])))
                              ],
                            ),
                          ),
                          Container(
                            height: Sizes.default20,
                            alignment: Alignment.bottomLeft,
                            // margin: const EdgeInsets.only(top: Sizes.default6),
                            child: Text(
                              '2023-03-10',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color797, fontSize: Sizes.default12),
                            ),
                          )
                        ],
                      ))
                    ],
                  ),
                ),
                Container(
                  padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
                  child: Row(
                    children: [
                      Text(
                        '商家：',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color797, fontSize: Sizes.default13),
                      ),
                      BrnRatingStar(
                          count: 5,
                          selectedCount: 3.5,
                          space: 3,
                          canRatingZero: true,
                          starBuilder: (RatingState state) {
                            return buildRating(state);
                          }),
                      const SizedBox(
                        width: Sizes.default10,
                      ),
                      Text(
                        '味道4星　包装5星',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default13, color: ColorsUtils.color797),
                      )
                    ],
                  ),
                ),
                Container(
                    alignment: Alignment.centerLeft,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '推荐：',
                            style: StylesUtils.customTextStyle(
                                color: ColorsUtils.color797, fontSize: Sizes.default13),
                          ),
                        ),
                        Expanded(
                            child: Container(
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '牛肉拌面、红烧狮子头、西湖醋鱼、白灼小河虾、清蒸黄花鱼',
                            style: StylesUtils.customTextStyle(
                                color: ColorsUtils.color797,
                                fontSize: Sizes.default13,
                                lineHeight: 1.5),
                          ),
                        ))
                      ],
                    )),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                  child: Text(
                    '一如既往的不错，比较清淡，适合南方人口味，我堂食买的一样。',
                    style: StylesUtils.customTextStyle(
                        color: ColorsUtils.color333, fontSize: Sizes.default15, lineHeight: 1.8),
                  ),
                ),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: const EdgeInsets.only(bottom: Sizes.default15),
                  child: Wrap(
                      spacing: Sizes.default10,
                      runSpacing: Sizes.default12,
                      children: urls
                          .map((e) => GFImageOverlay(
                                width: Sizes.default80,
                                height: Sizes.default80,
                                borderRadius: BorderRadius.circular(Sizes.default5),
                                image: NetworkImage(e),
                              ))
                          .toList()),
                ),
                Container(
                  alignment: Alignment.centerRight,
                  padding: const EdgeInsets.only(bottom: Sizes.default10),
                  child: Container(
                    constraints: const BoxConstraints.expand(
                        width: Sizes.default80, height: Sizes.default30),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        border: Border.all(
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6),
                        ),
                        color: ColorsUtils.rgba(255, 255, 255, 1),
                        borderRadius: BorderRadius.circular(Sizes.default5)),
                    child: TextButton(
                        onPressed: () {
                          Get.toNamed(RouteGet.evaluateReply);
                        },
                        child: Text(
                          '回复',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default13, color: ColorsUtils.colorFf6),
                        )),
                  ),
                )
              ],
            ),
          ),
          Container(
            decoration: const BoxDecoration(
              color: Colors.white,
            ),
            margin: const EdgeInsets.only(top: Sizes.default10),
            padding: const EdgeInsets.only(
                bottom: Sizes.default10,
                right: Sizes.default15,
                left: Sizes.default15,
                top: Sizes.default20),
            child: ListBody(
              children: [
                SizedBox(
                  height: Sizes.default40,
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      GFAvatar(
                        backgroundImage: ToolsUtils.assetImage('mine.png'),
                        size: GFSize.LARGE,
                      ),
                      Expanded(
                          child: Column(
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                'k**3',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                              ),
                              Text.rich(TextSpan(
                                  text: '详情',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color797, fontSize: Sizes.default12),
                                  children: [
                                    WidgetSpan(
                                        child: BrunoTools.getAssetSizeImage(BrnAsset.iconRightArrow,
                                            Sizes.default14, Sizes.default14),
                                        alignment: PlaceholderAlignment.middle)
                                  ]))
                            ],
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.only(top: Sizes.default8),
                            child: Text(
                              '2023-03-10',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color797, fontSize: Sizes.default12),
                            ),
                          )
                        ],
                      ))
                    ],
                  ),
                ),
                Container(
                  padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
                  child: Row(
                    children: [
                      Text(
                        '商家：',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color797, fontSize: Sizes.default13),
                      ),
                      BrnRatingStar(
                          count: 5,
                          selectedCount: 3.5,
                          space: 3,
                          canRatingZero: true,
                          starBuilder: (RatingState state) {
                            return buildRating(state);
                          }),
                      const SizedBox(
                        width: Sizes.default10,
                      ),
                      Text(
                        '味道4星　包装5星',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default13, color: ColorsUtils.color797),
                      )
                    ],
                  ),
                ),
                Container(
                    alignment: Alignment.centerLeft,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '推荐：',
                            style: StylesUtils.customTextStyle(
                                color: ColorsUtils.color797, fontSize: Sizes.default13),
                          ),
                        ),
                        Expanded(
                            child: Container(
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '牛肉拌面、红烧狮子头、西湖醋鱼、白灼小河虾、清蒸黄花鱼',
                            style: StylesUtils.customTextStyle(
                                color: ColorsUtils.color797,
                                fontSize: Sizes.default13,
                                lineHeight: 1.5),
                          ),
                        ))
                      ],
                    )),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                  child: Text(
                    '一如既往的不错，比较清淡，适合南方人口味，我堂食买的一样。',
                    style: StylesUtils.customTextStyle(
                        color: ColorsUtils.color333, fontSize: Sizes.default15, lineHeight: 1.8),
                  ),
                ),
                Container(
                  alignment: Alignment.centerRight,
                  padding: const EdgeInsets.only(bottom: Sizes.default10),
                  child: Container(
                    constraints: const BoxConstraints.expand(
                        width: Sizes.default80, height: Sizes.default30),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        border: Border.all(
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6),
                        ),
                        color: ColorsUtils.rgba(255, 255, 255, 1),
                        borderRadius: BorderRadius.circular(Sizes.default5)),
                    child: TextButton(
                        onPressed: () {},
                        child: Text(
                          '回复',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default13, color: ColorsUtils.colorFf6),
                        )),
                  ),
                )
              ],
            ),
          ),
          Container(
            decoration: const BoxDecoration(
              color: Colors.white,
            ),
            margin: const EdgeInsets.only(top: Sizes.default10),
            padding: const EdgeInsets.only(
                bottom: Sizes.default10,
                right: Sizes.default15,
                left: Sizes.default15,
                top: Sizes.default20),
            child: ListBody(
              children: [
                SizedBox(
                  height: Sizes.default40,
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      GFAvatar(
                        backgroundImage: ToolsUtils.assetImage('mine.png'),
                        size: GFSize.LARGE,
                      ),
                      Expanded(
                          child: Column(
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                'k**3',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                              ),
                              Text.rich(TextSpan(
                                  text: '详情',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color797, fontSize: Sizes.default12),
                                  children: [
                                    WidgetSpan(
                                        child: BrunoTools.getAssetSizeImage(BrnAsset.iconRightArrow,
                                            Sizes.default14, Sizes.default14),
                                        alignment: PlaceholderAlignment.middle)
                                  ]))
                            ],
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.only(top: Sizes.default8),
                            child: Text(
                              '2023-03-10',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color797, fontSize: Sizes.default12),
                            ),
                          )
                        ],
                      ))
                    ],
                  ),
                ),
                Container(
                  padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
                  child: Row(
                    children: [
                      Text(
                        '团购：',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color797, fontSize: Sizes.default13),
                      ),
                      BrnRatingStar(
                          count: 5,
                          selectedCount: 3.5,
                          space: 3,
                          canRatingZero: true,
                          starBuilder: (RatingState state) {
                            return buildRating(state);
                          }),
                      const SizedBox(
                        width: Sizes.default10,
                      ),
                      Text(
                        '味道4星　包装5星',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default13, color: ColorsUtils.color797),
                      )
                    ],
                  ),
                ),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: const EdgeInsets.only(bottom: Sizes.default15),
                  child: Wrap(
                      spacing: Sizes.default10,
                      runSpacing: Sizes.default12,
                      children: urls
                          .map((e) => GFImageOverlay(
                                width: Sizes.default80,
                                height: Sizes.default80,
                                borderRadius: BorderRadius.circular(Sizes.default5),
                                image: NetworkImage(e),
                              ))
                          .toList()),
                ),
                Container(
                  alignment: Alignment.centerRight,
                  padding: const EdgeInsets.only(bottom: Sizes.default10),
                  child: Container(
                    constraints: const BoxConstraints.expand(
                        width: Sizes.default80, height: Sizes.default30),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        border: Border.all(
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6),
                        ),
                        color: ColorsUtils.rgba(255, 255, 255, 1),
                        borderRadius: BorderRadius.circular(Sizes.default5)),
                    child: TextButton(
                        onPressed: () {},
                        child: Text(
                          '回复',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default13, color: ColorsUtils.colorFf6),
                        )),
                  ),
                )
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget buildRating(RatingState state) {
    switch (state) {
      case RatingState.select:
        return BrunoTools.getAssetSizeImage(BrnAsset.iconStar, Sizes.default14, Sizes.default14,
            color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6));
      case RatingState.half:
        return BrunoTools.getAssetSizeImage(BrnAsset.iconStarHalf, Sizes.default14, Sizes.default14,
            color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6));
      case RatingState.unselect:
      default:
        return BrunoTools.getAssetSizeImage(BrnAsset.iconStar, Sizes.default14, Sizes.default14,
            color: ColorsUtils.parseColorFromHexString('#A6A6A6'));
    }
  }
}
